<template>
  <div class="ycdwrap" id="ycdwrap">
    <div class="yc-table-wrp">
      <div>
        <yc-title  class="title" value="新增合同模板"></yc-title>
      </div>
      <el-form @submit.native.prevent :model="form" label-width="120px">
        <el-form-item label="模板所属公司" name="smallredstar">
          <el-select class="input" show-word-limit placeholder="请选择模板所属公司" v-model.trim="form.ip_name" style="width:48%; min-width: 440px;">
            <el-position></el-position>
          </el-select>
        </el-form-item>
        <el-form-item label="模板名称" name="smallredstar">
          <el-input class="input" maxlength="20" show-word-limit placeholder="请输入模板名称" v-model.trim="form.ip_name" style="width:48%; min-width: 440px;"></el-input>
        </el-form-item>
        <el-form-item label="合同内容" name="smallredstar">
          <div class="fuwenben">
            <quill-editor ref="text" v-model="form.content" style="min-height: 480px;" class="myQuillEditor" :options="form.editorOption" />
          </div>
        </el-form-item>
        <el-form-item label=" ">
          <el-button @click="handlePreservation" class="cancel" >取消</el-button>
          <el-button @click="handlePreservation" class='keep'>保存</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import request from 'request'
import { quillEditor } from 'vue-quill-editor'
import ycTitle from '@/components/ycTitle.vue'
import ycInput from '@/components/yc-input.vue'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
import ycSearchButton from '@/components/searchButton.vue'
export default {
  name: 'codeManagement',
  components: {
    ycTitle,
    ycSearchButton,
    ycInput,
    quillEditor
  },
  data () {
    return {
      active1: true,
      active2: false,
      fansNewAdd: [],
      form: {
        ip_name: '',
        designer: '',
        imageUrl: [],
        xingge: '',
        data: '',
        imageName: '',
        content: '',
        editorOption: {},
        pcradio: '1',
        fansArr: [
          {
            fansName: '抖音',
            fansVal: ''
          },
          {
            fansName: '微博',
            fansVal: ''
          },
          {
            fansName: '微信',
            fansVal: ''
          }
        ]
      }
    }
  },
  methods: {
    handleDele () {
      this.form.imageUrl = []
    },
    handlePreservation (e) {
      let result
      if (this.form.good_code) {
        let patrn = /^\d+(\.\d+)?$/
        result = patrn.test(this.form.good_code)
        if (result === false) {
          this.$message.error('商品编码只能输入数值类型')
          return
        }
      }

      if (!this.form.good_name) {
        this.$message.error('请输入商品名称')
        return
      } else if (!this.form.good_code) {
        this.$message.error('请输入商品编码')
        return
      }
      if (!this.form.imageName) {
        this.$message.error('上传失败')
        return
      }

      var data = {
        goodCode: this.form.good_code,
        goodImage: this.form.imageName,
        goodName: this.form.good_name
      }
      request.uploadimg(data).then(res => {
        this.$message({
          message: '添加成功',
          type: 'success'
        })
        setTimeout(() => {
          this.$router.push('/goodsList')
        }, 300)
      }).catch(e => {
        this.$message.error('添加失败')
      })
      this.form.good_code = ''
      this.form.imageName = ''
      this.form.good_name = ''
      this.form.imageUrl = []
    },
    handleUpload (file, fileList) {
      this.form.data = file
      this.form.imageUrl[0] = URL.createObjectURL(file.raw)
      this.$forceUpdate()
    },
    handleAvatarSuccess (response, file, fileList) {
      this.form.imageName = response.fileName
    },
    beforeAvatarUpload (file) {
      const isLt2M = file.size / 1024 / 1024 < 10
      if (!isLt2M) {
        this.$message.error('商品图片大小不能超过 10MB!')
        this.form.imageUrl = []
        this.form.imageName = ''
      }
      return isLt2M
    },
    // 新增到fans数组
    newpush () {
      this.fansNewAdd.push({})
    },
    // 删除当前元素
    delNowDom (index) {
      this.fansNewAdd.splice(index, 1)
      console.log(this.fansNewAdd)
    }
  },
  computed: {
    setUrl () {
      var url = process.env.BASE_ROOT + '/dealer/goods/uploadimg'
      return url
    },
    headers () {
      return {
        'Authorization': 'Bearer ' + localStorage.getItem('ycd_token')
      }
    }
  }
}
</script>

<style lang="stylus" scoped="scoped">
.yc-table-wrp{
  .title{
    margin 0 0 20px 0
  }
  .preservation{
    width 100px
    height 30px
    font-size 16px
  }
}
</style>
<style lang="stylus">
.el-input__inner {
  padding: 0 50px 0 15px;
}
.el-form-item__label {
  text-align: left;
}
.avatar-uploader{
  display: inline-block;
}
.avatar-uploader .el-icon-label{
  position: absolute;
  top: -6px;
  right: -15px;
  display: block;
  width: 46px;
  height: 26px;
  background-color: #13ce66;
  transform: rotate(45deg);
  z-index: 99;
}
.avatar-uploader .el-icon-label .el-cion{
  position: absolute;
  transform: rotate(-45deg);
  top: 40%;
  right: 34%;
  color: #FFFFFF;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  margin: 0 10px 0 0;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  width: 178px;
  height: 178px;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.el-textarea__inner {
  min-height: 40px;
}
#ycdwrap .el-form-item__content .input {
  height: auto;
  min-height: 40px;
}
#ycdwrap .fansAddBox .el-input__inner {
  padding: 0 25px 0 10px;
}
#ycdwrap div[name="smallredstar"] .el-form-item__label:after {
  content: '*';
  color: red;
  margin-left: 5px;
}
#ycdwrap .el-form-item__content .el-textarea textarea::-webkit-scrollbar-track-piece
  background-color rgba(0, 0, 0, 0)
  border-left 1px solid rgba(0, 0, 0, 0)
#ycdwrap .el-form-item__content .el-textarea textarea::-webkit-scrollbar
  width 4px
  height 8px
  border-radius 4px
#ycdwrap .el-form-item__content .el-textarea textarea::-webkit-scrollbar-thumb
  background-color rgba(0, 0, 0, 0.1)
  background-clip padding-box
  border-radius 4px
  min-height 10px
#ycdwrap .el-form-item__content .el-textarea textarea::-webkit-scrollbar-thumb:hover
  background-color rgba(0, 0, 0, 0.2)
  border-radius 4px
#ycdwrap .el-form-item__content .el-textarea .el-input__count {
  bottom: 0;
  line-height: 20px;
  background-color: transparent;
}
.fuwenben .ql-container.ql-snow {
  border: 0;
}
.ql-toolbar.ql-snow {
  border-bottom: 1px solid #DCDFE6;
  border-top: 0;
  border-left: 0;
  border-right: 0;
}
.fuwenben{
  border: 1px solid #DCDFE6;
  border-radius: 4px;
}
.fuwenben .ql-editor {
  min-height: 120px;
}
</style>

<style lang="stylus" scoped="scoped">
@import '~styles/varibles.styl'
.avatar{
  width: 178px;
  height: 178px;
  display: block;
}
.fansWrap {
  max-width: 710px;
  min-width: 632px;
  padding: 30px;
  box-sizing: border-box;
  background-color: $bgTabCont;
}
.fansBox {
  position relative
}
.fansInputBox, .fansAddBox {
  overflow hidden
  margin-top 15px
}
.fansAddBtn {
  width 30px
  height 30px
  padding 0
  border-radius 30px
  position absolute
  top 5px
  right 0
}
.fansInputContainer {
  padding-bottom 15px
}
.fansInputBox .fansInputContainer:last-child {
  padding-bottom 0
}
.delNewInput{
  display inline-block
  font-size 14px
  color #FF6600
  line-height 40px
  cursor pointer
}
</style>
